package com;


import java.text.ParseException;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.*;

public class StaticDemo<E> {
    static Stack<Number> numberStack = new Stack<>();

    public static void main(String[] args) throws Exception {

        // System.out.println(getDate("2019-11-01 00:00:00","yyyy-MM-dd HH:mm:ss"));
        String aa = "啊啊啊";
        System.out.println("utf-8=>" + aa.getBytes("UTF-8"));
        System.out.println("utf-16=>" + aa.getBytes("UTF-16").length);
        System.out.println("192.168.1.100".substring(0, "192.168.1.100".lastIndexOf('.')));

          Thread  thread =  new Thread(new Runnable() {
                @Override
                public void run() {
                    int i = 1;
                    while (i < 10000) {
                        System.out.println(i);
                        if (i == 50) {
                           throw new RuntimeException("线程内部异常") ;
                        }
                        i++;
                    }
                }
            });
          thread.start();

        try {
            thread.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler(){

                @Override
                public void uncaughtException(Thread t, Throwable e) {

                }
            });
        } catch (Throwable e) {
            System.out.println("捕获异常");
        }
        System.out.println("线程异常");
    }

    public static void popAll(Stack<? super Long> stack) {
        while (!stack.empty()) {
            System.out.println(stack.pop());
        }
    }

    //dataFormate yyyy-MM-dd HH:mm:ss
    public static Date getDate(String dateInfo, String dataFormat) {
        SimpleDateFormat formatter = new SimpleDateFormat(dataFormat);
        ParsePosition pos = new ParsePosition(0);
        Date date = formatter.parse(dateInfo, pos);
        return date;
    }

    public static void testMap() {
        Map<String, String> map = new HashMap();
        int i = 1;
        do {
            String seatNo = String.format("%02d", i);
            String idCardEnd6 = String.format("%06d", i);
            if (i <= 50) {
                //String idCardEnd6e = String.format("%05d", i);
                //String idCardEnd6f = String.format("%05d", i);
                map.put(seatNo + "T", "0001" + seatNo);
                map.put(seatNo + "B", "0002" + seatNo);
                map.put(seatNo + "D", "0003" + seatNo);
                map.put(seatNo + "E", "0004" + seatNo);
                map.put(seatNo + "F", "0005" + seatNo);
            }
            map.put(seatNo + "A", idCardEnd6);
            i++;
        }
        while (i < 100);

        map.keySet().stream().sorted().forEach((k) -> {
            System.out.println("key:" + k + " value:" + map.get(k));
        });
    }
}
